package com.roin.learn.activiti.base;

import com.roin.learn.activiti.entity.User;
import com.roin.learn.activiti.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;

public class BaseController {
    protected static final String ERROR="error";
    protected final Logger log = LoggerFactory.getLogger(getClass());


    public User checkLogin(HttpSession session) throws BusinessException{
        ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
        User user = (User) session.getAttribute(SysConstent.SESSION_LOGIN_USER_KEY);
        if (user==null)
            throw new BusinessException(SysConstent.MSG_RELOGIN);
        return user;
    }
    public User checkLogin() throws BusinessException{
        HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
        User user = (User) session.getAttribute(SysConstent.SESSION_LOGIN_USER_KEY);
        if (user==null)
            throw new BusinessException(SysConstent.MSG_RELOGIN);
        return user;
    }
}
